package com.manopservice.dao;

import java.util.List;

import com.manopservice.model.CarType;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("carTypeDAO")
public class CarTypeDAOImpl implements CarTypeDAO {

	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public void save(CarType carType) {
		sessionFactory.getCurrentSession().saveOrUpdate(carType);
		
	}
	
	@Override
	public void delete(int id) {
		CarType carType = (CarType) sessionFactory.getCurrentSession().get(CarType.class, id);
		sessionFactory.getCurrentSession().delete(carType);
		
	}

	@SuppressWarnings("unchecked")
	public List<CarType> findAll() {
		
		return (List<CarType>) sessionFactory.getCurrentSession().createCriteria(CarType.class).list();
	}

	@Override
	public CarType findById(int id) {
		return (CarType) sessionFactory.getCurrentSession().get(CarType.class, id);
	}	
			
}
